package com.cy.pj.common.web;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalTime;

public class TimeAccessInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler){
        LocalTime now = LocalTime.now();
        int hour = now.getHour();
        if(hour<=6 || hour>=22)
            throw new RuntimeException("请在6~22点进行访问");
        return true;
    }
}
